package algotithm.leetcode.dichotomy.test1351;

import java.util.Scanner;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/8-9:42
 */
public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] grid = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                grid[i][j] = scanner.nextInt();
            }
        }
        scanner.close();
        Solution solution = new Solution();
        int count = solution.countNegatives(grid);
        System.out.println(count);
    }

    public int countNegatives(int[][] grid) {
        int sum = 0;
        for (int i = 0; i < grid.length; i++) {
            sum += count(grid[i]);
        }
        return sum;
    }

    public int count(int[] nums) {
        int l = 0, r = nums.length - 1;
        int res = 0;
        if (nums[r] >= 0) {
            return 0;
        }
        while (l <= r) {
            int mid = l + r >> 1;
            if (nums[l] < 0) {
                res++;
                l++;
            } else if (nums[mid] >= 0) {
                l = mid + 1;
            } else {
                l++;
            }
        }
        return res;
    }


}
